<?php

namespace app\admin\controller;

use app\BaseController;
use think\facade\View;

/**
 * 验证是否登录，登录后进行基本数据处理
 * 
 * 时间 ： 2020年3月10日13:27:05
 * 作者 ： 夏立军
 */
class AdminBase extends BaseController
{
    public function __construct()
    {
        // 用来处理登录的结果，如果失败则 重新登录
        if (!session('?admin_login')) {
            // 记住当前地址并重定向
            return redirect_test(url('Login/index'));
        }

        self::admin_config();
    }

    // 这些配置都是给前端页面使用的
    private function admin_config()
    {
        //session 数据
        View::assign('admin_info', session('admin_login'));
        // 系统名称
        View::assign('system_name', config('ams_config.system_name'));

        $admin_list = [
            ['name' => '首页', 'icon' => 'am-icon-home', 'url' => url('index/index')],
            ['name' => '个人信息', 'icon' => 'am-icon-info-circle', 'url' => url('admin/index')],
            ['name' => '成果管理', 'icon' => 'am-icon-cogs', 'url' => url('AchievementManage/index')],
            // ['name' => '成果分析', 'icon' => 'am-icon-bar-chart', 'url' => url('index/index')],
            ['name' => '用户管理', 'icon' => 'am-icon-user-plus', 'url' => url('User/index')],
            ['name' => '角色管理', 'icon' => 'am-icon-user', 'url' => url('Role/index')],
            // ['name' => '权限管理', 'icon' => 'am-icon-indent', 'url' => url('Permissions/index')],
            ['name' => '通知管理', 'icon' => 'am-icon-list-alt', 'url' => url('Notice/index')],
            ['name' => '轮播图管理', 'icon' => 'am-icon-image', 'url' => url('Slideshow/index')],
            // ['name' => '查看图标', 'icon' => 'am-icon-cogs', 'url' => url('index/icon')],
            //['name' => '查看图标2', 'icon' => 'am-icon-cogs', 'url' => url('index/icon2')],
            ['name' => '退出', 'icon' => 'am-icon-sign-out', 'url' => url('login/logOut')],
        ];

        $kaifa_list = [
            ['name' => '首页', 'icon' => 'am-icon-home', 'url' => url('index/index')],
            ['name' => '个人信息', 'icon' => 'am-icon-info-circle', 'url' => url('admin/index')],
            ['name' => '成果管理', 'icon' => 'am-icon-cogs', 'url' => url('AchievementManage/index')],
            // ['name' => '成果分析', 'icon' => 'am-icon-bar-chart', 'url' => url('index/index')],
            ['name' => '用户管理', 'icon' => 'am-icon-user-plus', 'url' => url('User/index')],
            ['name' => '角色管理', 'icon' => 'am-icon-user', 'url' => url('Role/index')],
            ['name' => '权限管理', 'icon' => 'am-icon-indent', 'url' => url('Permissions/index')],
            ['name' => '通知管理', 'icon' => 'am-icon-list-alt', 'url' => url('Notice/index')],
            ['name' => '轮播图管理', 'icon' => 'am-icon-image', 'url' => url('Slideshow/index')],
            // ['name' => '查看图标', 'icon' => 'am-icon-cogs', 'url' => url('index/icon')],
            //['name' => '查看图标2', 'icon' => 'am-icon-cogs', 'url' => url('index/icon2')],
            ['name' => '退出', 'icon' => 'am-icon-sign-out', 'url' => url('login/logOut')],
        ];

        // 分类配置
        if(session('admin_login')->id == 1){
            View::assign('classify', $kaifa_list);
        }else{
            View::assign('classify', $admin_list);
        }
        
    }
}
